package com.itheima.demo6;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

public class Demo {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", "heima001");
        map.put("name", "张三");
        map.put("age", 23);
        map.put("birthday", "1999-09-09");
        Class studentClass = Student.class;
        Student o = (Student) studentClass.getDeclaredConstructor().newInstance();

        map.forEach((k,v)->{
            try {
            Field declaredField = studentClass.getDeclaredField(k);
            declaredField.setAccessible(true);
                declaredField.set(o,v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        System.out.println(o);
    }
}
